using System.Collections;
using System.Collections.Generic;

namespace Commons.Loading
{
	public class BasicLoadingTask : ILoadingTask
	{
		public LoadingContainerTask Container { protected get; set; }

		public BasicLoadingTask (float weight = 0.0f)
		{
			IsAsync = (weight > 0);
			Weight = weight;
		}

		#region ILoadingTask implementation
		public virtual string Name
		{
			get
			{
				return GetType().Name;
			}
		}
		
		public string TaskId{get;set;}

		public bool IsAsync
		{
			get;
			protected set;
		}

		public float Weight
		{
			get;
			protected set;
		}
		
		public List<string> Required
		{
			get; 
			protected set; 
		}

		public virtual void Start()
		{
			Started = true;
		}

		public virtual void SetUp ()
		{
		}
		
		public virtual void TearDown ()
		{
		}
		
		public virtual IEnumerator Update ()
		{
			//Started = true;
			//Completed = true;
			yield break;
		}
		
		public virtual ILoadingTask Requires(params string[] requires)
		{
			Required = new List<string>();
			foreach(string dep in requires)
			{
				Required.Add(dep);	
			}
			return this;
		}
		
		
		public TaskCompletedCallback Callback
		{
			get;
			protected set;
		}
		public virtual ILoadingTask OnComplete(TaskCompletedCallback callback)
		{
			this.Callback = callback;
			return this;
		}
		
		public virtual float Progress
		{ 
			get
			{
				return Completed ? 1.0f : 0.0f;
			}
		}

		public virtual bool Completed  
		{ 
			get;
			set;
		}
		
		
		public virtual bool Started 
		{ 
			get; 
			protected set;
		}
		
		public virtual bool Halted 
		{ 
			get; 
			protected set;
		}
		
		public virtual bool Unlocked 
		{ 
			get; 
			protected set;
		}
		
		public void Unlock()
		{
			Unlocked = true;
		}
		
		#endregion
	}
}

